package licode.unisop.auth.infrastructure.service;

import licode.unisop.auth.domain.platform.gateway.PlatInfoGateway;
import licode.unisop.client.vo.SopAuthPlatform;
import licode.unisop.platform.client.api.SiPlatformAuthService;
import licode.unisop.platform.client.vo.PlatAuthVO;
import licode.unisop.provider.info.SiPlatIdFind;
import licode.unisop.provider.vo.SiPlatform;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author licode
 */
@Service
public class PlatInfoGatewayAuth implements PlatInfoGateway {
    @Resource
    private SiPlatformAuthService siPlatformAuthService;


    @Override
    public SopAuthPlatform getPlatAuthInfo(String platformId) {
        PlatAuthVO platAuth = siPlatformAuthService.fromId(SiPlatIdFind.builder().platformId(platformId).build());
        return null == platAuth ? null : SopAuthPlatform.builder()
                .realmId(platAuth.getRealmId())
                .platformId(platAuth.getPlatformId())
                .name(platAuth.getName())
                .modelToken(platAuth.getModelToken())
                .innerToken(platAuth.getInnerToken())
                .build();
    }

    @Override
    public SiPlatform getPlatformAndCheck(SiPlatIdFind idInfo) {
        return siPlatformAuthService.getPlatformAndCheck(idInfo);
    }
}
